import Bullet from "./bullet";


const { executeInEditMode, ccclass, property } = cc._decorator;

@ccclass
@executeInEditMode
export default class BulletWorldEdge extends cc.Component {
    @property
    side = 0; //上 右 下 左

    @property
    weight = 200;
    protected onLoad(): void {
        let worldNode = this.node.parent;
        worldNode.on(cc.Node.EventType.SIZE_CHANGED, this.updateAlign, this);
    }
    updateAlign() {
        let worldNode = this.node.parent;

        switch (this.side) {
            case 0:
                this.node.width = worldNode.width;
                this.node.height = this.weight;
                this.node.x = -worldNode.width * worldNode.anchorX + this.node.width / 2;
                this.node.y = worldNode.height * (1 - worldNode.anchorY) + this.node.height / 2;
                this.node.width += this.weight * 2;
                break;
            case 1:
                this.node.width = this.weight;
                this.node.height = worldNode.height;
                this.node.x = worldNode.width * (1 - worldNode.anchorX) + this.node.width / 2;
                this.node.y = worldNode.height * (1 - worldNode.anchorY) - this.node.height / 2;
                break;
            case 2:
                this.node.width = worldNode.width;
                this.node.height = this.weight;
                this.node.x = -worldNode.width * worldNode.anchorX + this.node.width / 2;
                this.node.y = -worldNode.height * worldNode.anchorY - this.node.height / 2;
                this.node.width += this.weight * 2;
                break;
            case 3:
                this.node.width = this.weight;
                this.node.height = worldNode.height;
                this.node.x = -worldNode.width * worldNode.anchorX - this.node.width / 2;
                this.node.y = worldNode.height * (1 - worldNode.anchorY) - this.node.height / 2;
                break;
        }
    }
    protected update(dt: number): void {
        if (CC_EDITOR) {
            this.updateAlign();
        }
    }
};